<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('订单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								姓名：<input type="text" name="name"/>
							</li>

							<li>
								手机号：<input type="text" name="phone"/>
							</li>

							<li>
								状态：
								<select name="status" th:with="type=${@dict.getType('orderStatus')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>


							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:order:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="system:order:edit">
					<i class="fa fa-edit"></i> 修改
				</a>
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:order:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:order:export">
						<i class="fa fa-download"></i> 导出
				 </a>
				<a class="btn btn-primary btn-edit disabled" onclick="acceptOrder()" shiro:hasPermission="system:order:accept">
					<i class="fa fa-edit"></i> 接单
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="confirm('fk')" shiro:hasPermission="system:order:confirm">
					<i class="fa fa-edit"></i> 确认放款
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="refuseOrder()" shiro:hasPermission="system:order:refuse">
					<i class="fa fa-edit"></i> 作废
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="confirm('hk')" shiro:hasPermission="system:order:confirm">
					<i class="fa fa-edit"></i> 确认回款
				</a>
			</div>
			<div class="col-sm-12 select-table table-striped" style="white-space: nowrap;" >
				<table id="bootstrap-table" data-mobile-responsive="true" style="table-layout:fixed"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:order:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:order:remove')}]];
        var prefix = ctx + "crm/order";
		// 获取数据字典数据
		var datasSex = [[${@dict.getType('sys_user_sex')}]];
		var datasDkType = [[${@dict.getType('dkType')}]];
		var datasHkType = [[${@dict.getType('hkType')}]];
		var dataOrderStatus = [[${@dict.getType('orderStatus')}]];
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "订单",
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'orderId', 
					title : '编号',
					visible: true,
					align: 'center',
					width:60
				},
				{
					field : 'status',
					title : '状态',
					align: 'center',
					width:130,
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(dataOrderStatus, value);
					}
				},
				{
					field : 'createBy',
					title : '创建者',
					align: 'center',
					width:100
				},
				{
					field : 'createTime',
					title : '创建时间',
					sortable: true,
					align: 'center',
					width:130
				},
				{
					field : 'name', 
					title : '姓名',
					align: 'center',
					width:130
				},
				{
					field : 'phone', 
					title : '手机号',
					align: 'center',
					width:130
				},
				{
					field : 'sex', 
					title : '性别',
					align: 'center',
					width:50,
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(datasSex, value);
					}
				},
				{
					field : 'idCard', 
					title : '身份证号',
					align: 'center',
					width:150
				},
				{
					field : 'birthday', 
					title : '出生日期',
					sortable: true,
					align: 'center',
					width:130,
					formatter: function (value, row, index) {
						//只显示日期
						if($.common.isNotEmpty(value)){
							return value.substring(0,10);
						}else{
							return "无";
						}
					}
				},
				{
					field : 'signTime', 
					title : '签约时间',
					sortable: true,
					align: 'center',
					width:130,
					formatter: function (value, row, index) {
						//只显示日期
						if($.common.isNotEmpty(value)){
							return value.substring(0,10);
						}else{
							return "无";
						}
					}
				},
				{
					field : 'managerName',
					title : '客服经理',
					align: 'center',
					width:100
				},
				{
					field : 'dkType', 
					title : '贷款方式',
					align: 'center',
					width:100,
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(datasDkType, value);
					}
				},
				{
					field : 'hkType', 
					title : '还款方式',
					align: 'center',
					width:100,
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(datasHkType, value);
					}
				},
				{
					field : 'applyMoney', 
					title : '申请金额',
					sortable: true,
					align: 'center',
					width:100,
					formatter: function (value, row, index) {
						return value + "万元";
					}
				},
				{
					field : 'period', 
					title : '还款期数',
					sortable: true,
					align: 'center',
					width:60,
					formatter: function (value, row, index) {
						return value + "期";
					}
				},
				{
					field : 'serviceMoney', 
					title : '信息服务费',
					sortable: true,
					align: 'center',
					width:100,
					formatter: function (value, row, index) {
						return value + "元";
					}
				},
				{
					field : 'remark',
					title : '备注',
					align: 'center',
					width:200,
				},
		        {
		            title: '操作',
		            align: 'center',
					align: 'center',
					width:200,
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.orderId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.orderId + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });

        //接单
		function acceptOrder(){
			$.modal.confirm("确定接单吗？", function() {
				var row = $('#bootstrap-table').bootstrapTable('getSelections')[0];
				var id = row.orderId;
				var url = prefix + "/acceptOrder";
				var data = { "id": id };
				$.operate.submit(url, "post", "json", data);
			});
		}

		//作废
		function refuseOrder(){
			$.modal.confirm("确定作废吗？", function() {
				var row = $('#bootstrap-table').bootstrapTable('getSelections')[0];
				var id = row.orderId;
				var url = prefix + "/refuse";
				var data = { "id": id };
				$.operate.submit(url, "post", "json", data);
			});
		}

		//确认放款或回款
		function confirm(code){
			var row = $('#bootstrap-table').bootstrapTable('getSelections')[0];
			if ($.common.isEmpty(row)) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			var id = row.orderId;
			var url = prefix + "/goConfirm?id="+id+"&code="+code;
			var title = "";
			if(code == "fk"){
				title = "确认放款";
			}else if(code == "hk"){
				title = "确认回款";
			}
			$.modal.open(title, url, "800", "300");
		}
    </script>
</body>
</html>